package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DaFuWngListener implements ICrossUnionSyncListener {

    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {

        List<CrossUnionMember> serverMemberList = new ArrayList<>();
        List<Long> serverMemberIdList = new ArrayList<>();
        for (CrossUnionMember member : memberList) {
            if(member.getServerId() != GameServer.getInstance().getServerId()){
                continue;
            }
            serverMemberList.add(member);
            serverMemberIdList.add(member.getUserId());
            if(syncType == eUnionSyncType.QuitUnion.getValue() || syncType == eUnionSyncType.BeKick.getValue() || syncType == eUnionSyncType.DeleteUnion.getValue()){
                DaFuWengMgr.notifyEmptyUnionData(Collections.singletonList(member.getUserId()), unionInfo.getUnionUid());
            }
        }

        if(syncType == eUnionSyncType.QuitUnion.getValue() || syncType == eUnionSyncType.BeKick.getValue()){
            DaFuWengMgr.unionMemberChange(serverMemberIdList);
        }

    }
}
